import request from '../../utils/request'
import { download } from '../../utils/commons'
import constants from '../../utils/Constants'

// 分页查询结算单列表
export async function getStatementsList({ status, stateno, customerno, minamount, maxamount, creator, beginTime, endTime, page }) {
    return request(apiPath.zbtie + "/api/statements", {
        method: 'get',
        data: { status, stateno, customerno, minamount, maxamount, creator, beginTime, endTime, page: page.page, size: page.size }
    });
}

// 分页查询结算单列表
export async function getCstIdStatementsList({ status, stateno, cstId, minamount, maxamount, creator, beginTime, endTime, page }) {
    return request(apiPath.zbtie + "/api/statements/" + cstId, {
        method: 'get',
        data: { status, stateno, cstId, minamount, maxamount, creator, beginTime, endTime, page: page.page, size: page.size }
    });
}


//结算单审批
export async function doApproval({ id, approvalresult, approvalmemo }) {
    return request(apiPath.zbtie + "/api/statement/" + id + "/approval", {
        method: 'post',
        data: { approvalresult, approvalmemo, appCode: constants.APPCODE }
    });
}


// 结算单付款
export async function pay({ id, stateid, filename, status, url, memo }) {
    return request(apiPath.zbtie + "/api/statement/" + id + "/pay", {
        method: 'post',
        data: { stateid, filename, status, url, memo }
    });
}

// 更新结算单
export async function updateStatus({ id, status }) {
    return request(apiPath.zbtie + "/api/statement/" + id + "/status", {
        method: 'post',
        data: { id, status }
    });
}

// 结算单信息查询
export async function getStatementById({ id }) {
    return request(apiPath.zbtie + "/api/statement/" + id, {
        method: 'get'
    });
}


// 结算单付款信息查询
export async function getPayById({ id }) {
    return request(apiPath.zbtie + "/api/statement/" + id + "/pay", {
        method: 'get',
    });
}

//分页结算单审核信息查询
export async function getApprovalById({ id, page }) {
    return request(apiPath.zbtie + "/api/statement/" + id + "/approval", {
        method: 'get',
        data: { page: page.page, size: page.size }
    });
}



// 增加结算单
export async function addStatement({ type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, orderIds, historyAmtIds, forexIds, depositids, payman, memo, orderChargesIds }) {
    return request(apiPath.zbtie + "/api/statement/" + type, {
        method: 'post',
        data: { type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, orderIds, historyAmtIds, forexIds, depositids, payman, memo, orderChargesIds }
    });
}

//增加结算单-市场采购
export async function createMpStatement({ type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, payman, memo, orderIds, historyAmtIds, forexIds, depositids, orderChargesIds, statementMpStr }) {
    return request(apiPath.zbtie + "/api/statementMp/" + type, {
        method: 'post',
        data: ({ type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, payman, memo, orderIds, historyAmtIds, forexIds, depositids, orderChargesIds, statementMpStr })
    });
}

// 导出excel

export async function exportStatement({ id }) {
    let url = apiPath.zbtie + `/api/${id}/export`;
    download(url, { statementId: id, filename: '付款申请表' });

}

// 导出excel
export async function exportStatementList({ status, stateno, customerno, minamount, maxamount, beginTime, endTime }) {
    let url = apiPath.zbtie + "/api/report/statements/export";
    download(url, { status, stateno, customerno, minamount, maxamount, beginTime, endTime, filename: '付款记录信息表' });

}
